<div class="layuimini-main">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label">学号</label>
            <div class="layui-input-block">
                <input type="text" name="role" autocomplete="off" class="layui-input" value="学号" id="userName-input-text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="role" autocomplete="off" class="layui-input" value="姓名" id="fullName-input-text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <input type="text" name="role" autocomplete="off" class="layui-input" value="角色" id="role-input-text">
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>所管理专业</legend>
        </fieldset>

        <table class="layui-hide" id="managedMajorsTableId" lay-filter="managedMajorsTableFilter"></table>

    </div>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate','miniPage','element','table'], function() {
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate,
            table=layui.table,
            miniPage = layui.miniPage;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //学生信息初始化
        //不允许修改部分内容
        jq1111('#role-input-text').attr("disabled","disabled");
        jq1111('#userName-input-text').attr("disabled","disabled");
        jq1111('#fullName-input-text').attr("disabled","disabled");

        //定义变量
        var userId=localStorage.getItem('selectedUserId');
        var userData;
        //获取学生信息
        jq1111.ajax({
            type: "GET",
            async:false,
            crossDomain:true,
            url: BasePath+"api/Account/",
            contentType: "application/json",
            xhrFields: {
                withCredentials: true
            },
            success:function (message) {
                console.log(message);
                userData=message.data;
                layer.msg(message.msg, function () {
                });
            },
            error:function (message) {
                console.log(message.responseJSON);
                layer.msg('失败:'+message.responseJSON.msg);
            },
        });
        //给表单赋值
        //学号 姓名 角色 赋初值
        jq1111('#userName-input-text').val(userData.userName);
        jq1111('#fullName-input-text').val(userData.fullName);
        jq1111('#role-input-text').val(function (){
            var result="";
            var roles= userData.roles;
            roles.forEach(function (role) {
                result+=role;
                result+=" ";
            })
            return result;
        });

        table.render({
            elem: '#managedMajorsTableId',
            url:BasePath+"api/Account/",
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }]
            ,parseData: function(res){ //res 即为原始返回的数据
                var parsedData=[];
                console.log(res)
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.managedMajors.length, //解析数据长度
                    "data": res.data.managedMajors
                };
            },
            cols: [[
                {field: 'id', title: 'ID'},
                {field: 'name', title: '专业'},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

    });
</script>